package ordering.dyn;

import general.CPA.CPA;
import general.CPA.DynamicCPA;
import general.constraints.VariableConstraints;

public class RandomOrdering extends DynamicOrdering {

	byte first;
	public RandomOrdering(byte first) {
		super();
		this.first = first;
	}
	
	@Override
	public byte next(DynamicCPA p, byte agent, VariableConstraints c) {
		if (p.hasNext(agent)){
			return p.next(agent);
		} else {
			byte[] b = p.getUnassigned();
			int rand = (int)(Math.random()*(double)(b.length));
			return b[rand];
		}
	}

	@Override
	public boolean hasNext(CPA p, byte id) {
		return !p.isFull();
	}

	@Override
	public boolean isFirst(byte id) {
		return id==first;
	}

}
